<!--
 * @Author: wangming
 * @Date: 2021-04-22 17:56:33
 * @LastEditors: wangming
 * @LastEditTime: 2022-04-29 10:03:06
 * @Description: file content
-->
<template>
  <div>
    <div class="ks-row-middle mb20 lh1">
      <div class="mr10 g3">隐藏域</div>
      <i
        class="el-icon-circle-plus-outline iconcolor f20 poi"
        @click="addTag"
      ></i>
    </div>
    <el-table
      :data="value.__config.formKeys"
      style="width: 100%"
      v-show="value.__config.formKeys.length > 0"
    >
      <el-table-column prop="key" label="数据字段"> </el-table-column>
      <el-table-column prop="value" label="值"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <span
            class="iconfont iconbianji mr10 poi"
            @click="edit(scope.row)"
          ></span>
          <span
            class="iconfont iconicon_shanchu poi"
            @click="remove(scope.$index)"
          ></span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import basicmixins from "../basicmixins";
import Module from "./addModule";
import { mapActions, mapGetters } from "vuex";
export default {
  computed: {
    ...mapGetters(["getEntitymodelList"]),
    myEntitymodelList() {
      return this.getEntitymodelList.filter((i) => !i.builtIn);
    },
  },
  mixins: [basicmixins],
  created() {
    if (!this.value.__config?.formKeys) {
      this.$set(this.value.__config, "formKeys", []);
    }
  },
  methods: {
    ...mapActions(["setForm"]),
    remove(index) {
      this.value.__config.formKeys.splice(index, 1);
    },
    async edit(item) {
      let formId = this.value.__config.modelCode;
      let formList = this.value.children || [];
      this.$store.commit("changeFormList", formList);
      await this.setForm(formId);
      Module.editForm(item, {
        myEntitymodelList: this.myEntitymodelList,
        tagName: this.value.tagName,
      }).then((res) => {
        Object.assign(item, res);
      });
    },
    async addTag() {
      let formId = this.value.__config.modelCode;
      let formList = this.value.children || [];
      this.$store.commit("changeFormList", formList);
      await this.setForm(formId);
      Module.addForm({
        myEntitymodelList: this.myEntitymodelList,
        tagName: this.value.tagName,
      }).then((o) => {
        this.value.__config.formKeys.push(o);
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
